package com.sikaryofficial.system.api.factory;

import com.sikaryofficial.common.core.domain.R;
import com.sikaryofficial.common.core.web.domain.PageResult;
import com.sikaryofficial.system.api.RemoteArticleService;
import com.sikaryofficial.system.api.model.infomation.ArticleDTO;
import com.sikaryofficial.system.api.model.infomation.ArticleListReq;
import com.sikaryofficial.system.api.model.infomation.KolListReq;
import com.sikaryofficial.system.api.model.infomation.StatuteListReq;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 文章服务降级处理
 *
 * @author qinjinyuan
 */
@Component
public class RemoteArticleFallbackFactory implements FallbackFactory<RemoteArticleService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteArticleFallbackFactory.class);

    @Override
    public RemoteArticleService create(Throwable throwable) {
        log.error("文章服务调用失败:{}", throwable.getMessage());
        return new RemoteArticleService() {
            /**
             * 查询文章列表
             *
             * @param req
             */
            @Override
            public PageResult<ArticleDTO> listPage(ArticleListReq req) {
                return PageResult.fail("article query error:" + throwable.getMessage());
            }

            @Override
            public PageResult<ArticleDTO> statuteListPage(StatuteListReq req) {
                return PageResult.fail("statute query error:" + throwable.getMessage());
            }

            /**
             * 查询kol列表
             *
             * @param req
             */
            @Override
            public PageResult<ArticleDTO> kolListPage(KolListReq req) {
                return PageResult.fail("kol query error:" + throwable.getMessage());
            }
            /**
             * 获取文章详细信息
             *
             * @param articleId
             */
            @Override
            public R<ArticleDTO> getInfo(Long articleId) {
                return R.fail("获取文章详细信息失败:" + throwable.getMessage());
            }

            @Override
            public R<ArticleDTO> getSimpleInfo(Long articleId) {
                return R.fail("获取文章简单详细信息失败:" + throwable.getMessage());
            }

            /**
             * 删除文章
             *
             * @param articleIds
             */
            @Override
            public R<Boolean> remove(String articleIds) {
                return R.fail("删除文章失败:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> removeOwner(String articleIds) {
                return R.fail("removeOwner文章失败:" + throwable.getMessage());
            }
            /**
             * 个人最新发布文章列表
             *
             * @return
             */
            @Override
            public R<List<ArticleDTO>> ownerLatest() {
                return R.fail("ownerLatest error:" + throwable.getMessage());
            }
        };
    }
}
